#define _XOPEN_SOURCE

#include <stdio.h>
#include <sys/ipc.h>
#include <sys/shm.h>
int main(){
  key_t key = ftok("./", 0x666);
  if(key < 0){
    perror("ftok\n");
    return 1;
  }

  int shmid = shmget(key, 4096, IPC_CREAT);
  if(shmid < 0){
    perror("shmget\n");
    return 2;
  }
  char* mem = (char*)shmat(shmid, NULL, 0);//关联共享内存

  printf("%s\n",mem);

  shmdt(mem);//移除和共享内存的关联
  return 0;
}
